package com.miao.util.collection;

import com.miao.util.http.MObjectMapper;
import com.miao.util.json.JsonUtils;

import java.util.*;

/**
 * Created by miao on 2015/4/13.
 */
public class TestConverter {

    public static void main(String[] args) {
        List<Map> list = new ArrayList<Map>();
        Map map0 = new HashMap();
        map0.put("id", "0");
        map0.put("pid", "root");
        map0.put("name", "根节点");
        list.add(map0);
        Map map1 = new HashMap();
        map1.put("id", "1");
        map1.put("pid", "0");
        map1.put("name", "节点1");
        list.add(map1);
        Map map2 = new HashMap();
        map2.put("id", "2");
        map2.put("pid", "0");
        map2.put("name", "节点2");
        list.add(map2);
        Map map3 = new HashMap();
        map3.put("id", "3");
        map3.put("pid", "1");
        map3.put("name", "节点3");
        list.add(map3);
        Map map4 = new HashMap();
        map4.put("id", "4");
        map4.put("pid", "1");
        map4.put("name", "节点4");
        list.add(map4);
        System.out.println(JsonUtils.toJson(list, new MObjectMapper()));
        Collection collection = Converter.List2Tree(list, null, "id", "pid", "children", "id|name");
        System.out.println(JsonUtils.toJson(collection, new MObjectMapper()));
    }

}
